import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@/styles/index.scss'

// 添加全局路由守卫
router.beforeEach((to, from, next) => {
  // 获取本地token值
  let token = localStorage.getItem('mytoken')
  // 判断是否有token
  if (token) {
    next()
  } else {
    // 如果访问的地址不是login就让它去login
    if (to.path !== '/login') {
      next({ path: '/login' })
    } else {
      next()
    }
  }
})
Vue.config.productionTip = false
Vue.config.devtools = true

Vue.use(ElementUI)
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
